import os
import requests
from selenium import webdriver

def get_reqponse(html_url):
    cookies = get_cookies(html_url)
    reponse = requests.get(html_url,cookies=cookies)
    return reponse


def get_cookies(url):
    driver = webdriver.Chrome()
    driver.get(url)
    cookies = driver.get_cookies()

    print(cookies)
    page_content = driver.page_source
    # print(page_content)
    save_web_page(page_content)
    driver.quit()

def save_web_page(content):
    path = f"html/"
    if not os.path.exists(path):
        os.makedirs(path)
    with open(path + "test.html", "w", encoding="utf-8") as f:
        f.write(content)


if __name__ == '__main__':
    url = f"https://blog.csdn.net/captain5339/article/details/125403282"
    # cookies = get_cookies(url)
    rep = get_reqponse(url)

    print(f"reponse:{rep.status_code}")
    print(f"reponse:{rep.encoding}")
    print(f"reponse:{rep.text}")
    print(f"reponse:{rep.content}")